﻿using Aker;
using Aker.DevTeam;
using DevExpress.XtraEditors.Repository;
using Extensions;
using System;
using System.Data;


namespace Cikislar
{
    public partial class YeniCikis : XForm
    {

        int cariId = -1;
        public YeniCikis(int CariId = -1)
        {
            InitializeComponent();
            this.cariId = CariId;
        }
        private void YeniHammaddeCikis_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("CikisTipiId", typeof(int));
            dt.Columns.Add("CikisTipi", typeof(string));
            dt.Rows.Add(1, "Depo");
            dt.Rows.Add(2, "Fason");
            dt.Rows.Add(3, "İşletmeye Çıkış");
            dt.Rows.Add(4, "Satış");
            gleCikisTipi.Properties.Assign(Utility.GetAutoCompGLE(dt, "CikisTipi", "CikisTipiId"));

            gleCikisTipi.EditValue = 4;
            if (cariId != -1)
                gleCari.EditValue = cariId;
            else
                gleCari.EditValue = 216;

            gleDepo.EditValue = null;
            gleDepo.Enabled = false;

            Data.TAM.DepoTableAdapter.Fill(Data.DB.Depo);
            gleDepo.Properties.Assign(Utility.GetAutoCompGLE(Data.DB.Depo, "Depo", "DepoId"));

            Data.TAM.CustomerTableAdapter.Fill(Data.DB.Customer);
            RepositoryItemGridLookUpEdit gle = Utility.GetAutoCompGLE(Data.DB.Customer, "Brand", "CustomerId");
            gle.View.EnableComplexFiltering("Brand");
            gleCari.Properties.Assign(gle);

            gleCikisTipi.EditValueChanged += gleCikisTipi_EditValueChanged;

            deCikis.EditValue = DateTime.Now;
        }

        void gleCikisTipi_EditValueChanged(object sender, EventArgs e)
        {
            int tip = gleCikisTipi.EditValue.ToIntNN();
            if (tip == 1)
            {
                gleCari.Enabled = false;
                gleCari.EditValue = null;
                gleDepo.Enabled = true;
            }
            else
            {
                gleCari.Enabled = true;
                gleDepo.Enabled = false;
                gleDepo.EditValue = null;
            }
        }

        private void btnKaydet_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        public int CikisTipiId { get { return gleCikisTipi.EditValue.ToIntNN(); } }
        public int DepoId { get { return gleDepo.EditValue.ToIntNN(); } }
        public int CariId
        {
            get { return gleCari.EditValue.ToIntNN(); }

        }
        public string Aciklama { get { return txtAciklama.Text; } }
        public DateTime CikisTarihi { get { return (DateTime)deCikis.EditValue; } }
    }
}
